<script type="text/javascript" src="<?php echo $vars['config']->wwwroot.'mod/'.WHITEBOARD_PLUGIN_DIR; ?>/js/jquery.raty/js/jquery.raty.min.js"></script>
<script type="text/javascript">
    function reRoutImgSrc(guid)
    {
        for (var i=1; i<=5; ++i)
        {
            if ($("#rate"+guid+"-"+i).attr("src") == "img/star-on.png")
                $("#rate"+guid+"-"+i).attr("src", "<?php echo $vars['config']->wwwroot.'mod/'.WHITEBOARD_PLUGIN_DIR; ?>/js/jquery.raty/img/star-on.png");
            if ($("#rate"+guid+"-"+i).attr("src") == "img/star-off.png")
                $("#rate"+guid+"-"+i).attr("src", "<?php echo $vars['config']->wwwroot.'mod/'.WHITEBOARD_PLUGIN_DIR; ?>/js/jquery.raty/img/star-off.png"); 
        }
    }
    
    function startRaty(guid)
    {
        $("#rate"+guid).html("");
        $("#rate"+guid).raty({
            click:function(score, event)
            {
                $.post("<?php echo $vars['config']->wwwroot.'mod/'.WHITEBOARD_PLUGIN_DIR; ?>/addrating.php",
                    {score:score, guid:guid},
                    function(avg)
                    {
                        $("#rate"+guid+"-avg").val(avg);
                        startRaty(guid);
                    }
                );
            },
            start:$("#rate"+guid+"-avg").val()
        });
        
        // A workaround to make raty work with elgg's complex routing
        reRoutImgSrc(guid);
        $(".rate"+guid).hover(
            function()
            {
                $(".rate"+guid).attr("src", "<?php echo $vars['config']->wwwroot.'mod/'.WHITEBOARD_PLUGIN_DIR; ?>/js/jquery.raty/img/star-off.png");
                var current_id = $(this).attr("id");
                current_id = current_id.charAt(current_id.length-1);
                for (var i=1; i<=current_id; ++i)
                    $("#rate"+guid+"-"+i).attr("src", "<?php echo $vars['config']->wwwroot.'mod/'.WHITEBOARD_PLUGIN_DIR; ?>/js/jquery.raty/img/star-on.png");
            },
            function(){}
        );
        $("#rate"+guid).hover(
            function(){},
            function()
            {
                reRoutImgSrc(guid);
            }
        );
    }
    
    $(function()
    {
        $("#tabs").tabs();
    });
</script>